#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include "fidata_list.h"

fidata_node *file_list_init()
{
	fidata_node *head;
	head = (fidata_node *)malloc(sizeof(fidata_node));
	head->next = NULL;
	if(head == NULL)
		exit(1);
	return head;
}

void fidata_node_insertion(fidata_node *node,fidata_node *head)
{
	fidata_node *p = malloc(sizeof(fidata_node));
	if(p==NULL)
		exit(1);
	memcpy(p,node,sizeof(fidata_node));
	p->next = head->next;
	head->next = p;
	return ;
}

int judge_user_duplicatefile(const char *string,fidata_node *head)
{
	fidata_node *p = head;
	p=p->next;
	while(p!=NULL){
		if(strcmp(string,p->buf)==0){
			return -1;
		}else{
			p=p->next;
		}
	}
	return 0;
}

fidata_node *list_return_filename(const char* name, fidata_node *head)
{
	fidata_node *p = head->next;
	while(p == NULL){
		if(strcmp(name,p->name)!=0){
			printf("%s\n",p->name);
			p=p->next;
		}
		else
			break;
	}
	return p;
}

void free_file_data(fidata_node *p)
{
	free(p);
	return ;
}
